package com.weixinadmin.dao;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class JdbcManager {

	  private static Logger logger = Logger.getLogger(JdbcManager.class);//log4j
		
	  private static JdbcTemplate jdbcTemplate;   
      private static NamedParameterJdbcTemplate namedParameterJdbcTemplate;   
	  private static SimpleJdbcTemplate simpleJdbcTemplate;   
	  
	  public JdbcManager(){   
		  
		  if(null != jdbcTemplate)
			  return ;
		  ApplicationContext ctx = new ClassPathXmlApplicationContext("springjdbc.xml");
		  DataSource dataSource = (DataSource)ctx.getBean("dataSource");
		  this.jdbcTemplate = new JdbcTemplate(dataSource);   
	      this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);   
	      this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);   
	  } 
	  public JdbcTemplate getjdbctemplate(){   
		 	return this.jdbcTemplate;
		 	   
	  } 
	  public String showjdbcTemplate(){
		  return jdbcTemplate.toString();
	  }
	 
}
